package com.example.intermediatecontrols;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class LoginDemoActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private Button btn_forgetPasswordOrSendVerifyCode;
    private EditText et_passwordOrVerifyCode;
    private TextView tv_passwordOrVerifyCode;
    private CheckBox ck_rememberPassword;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login_demo);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.loginDemo), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        // 隐藏ActionBar
        if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }
        //
        ck_rememberPassword = findViewById(R.id.ck_rememberPassword);
        btn_forgetPasswordOrSendVerifyCode = findViewById(R.id.btn_forgetPasswordOrSendVerifyCode);
        et_passwordOrVerifyCode = findViewById(R.id.et_passwordOrVerifyCode);
        tv_passwordOrVerifyCode = findViewById(R.id.tv_passwordOrVerifyCode);
        RadioGroup rg_login = findViewById(R.id.rg_login);
        rg_login.setOnCheckedChangeListener(this);
    }

    //监听单选变化
    @Override
    public void onCheckedChanged(@NonNull RadioGroup group, int checkedId) {
        if (checkedId == R.id.rb_passwordLogin) {
            btn_forgetPasswordOrSendVerifyCode.setText("忘记密码");
            et_passwordOrVerifyCode.setHint("请输入密码");
            tv_passwordOrVerifyCode.setText("密码:");
            ck_rememberPassword.setVisibility(View.VISIBLE);
        } else if (checkedId == R.id.rb_verifyCodeLogin) {
            btn_forgetPasswordOrSendVerifyCode.setText("发送验证码");
            et_passwordOrVerifyCode.setHint("请输入验证码");
            tv_passwordOrVerifyCode.setText("验证码:");
            ck_rememberPassword.setVisibility(View.GONE);
        }
    }
}